const nodemailer = require('nodemailer')

const sendEmail = async (options) => {
  // 创建transporter
  const transporter = nodemailer.createTransport({
    host: process.env.EMAIL_HOST, // 邮箱 SMTP 服务器
    port: process.env.EMAIL_PORT, // SMTP SSL 端口
    secure: true, // 使用 SSL
    auth: {
      user: process.env.EMAIL_USERNAME,
      pass: process.env.EMAIL_PASSWORD,
    },
  })

  // Email有关的选项
  const mailOptions = {
    from: 'from Akbar <akbar4857@qq.com>',
    to: options.email,
    subject: options.subject,
    text: options.message,
    // html:
  }

  // 用 nodemailer 发送邮件
  await transporter.sendMail(mailOptions)
}

module.exports = sendEmail
